<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数">
<input type="button" value="猜一猜" onclick="f()">
<input type="button" value="作弊" onclick="f1()">
<div id="d1"></div>
<script>
    let i = document.querySelector("input");
    let x = parseInt(Math.random() * 100) + 1;
    let d = document.querySelector("#d1");
    let count = 0;
    function f() {
        count++;
        if (isNaN(i.value)) {
            d.innerText = "输入错误";
        } else if (i.value > x) {
            d.innerText = "大了"

        } else if (i.value < x) {
            d.innerText = "小了"
        } else {
            d.innerText = "第" + count + "次对了!"
            count = 0;
            x = parseInt(Math.random()*100)+1;
        }
        i.value = "";
    }
    function f1() {
        d.innerText = x;
    }


</script>
</body>
</html>